package projet.volleystat;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class PlayerAdapter extends ArrayAdapter<Player> {
	protected List<Player> players;

	public PlayerAdapter(Context context, int ressource, List<Player> players) {
		super(context, ressource, players);
		this.players = players;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;

		if (v == null) {
			LayoutInflater vi = LayoutInflater.from(getContext());
			v = vi.inflate(R.layout.listitemlineplayer, null);
		}

		Player player = players.get(position);

		if (player != null) {
			TextView txtname = (TextView) v.findViewById(R.id.textname);
			TextView txtfirstname = (TextView) v
					.findViewById(R.id.textfirstname);
			TextView txtnationality = (TextView) v
					.findViewById(R.id.textnation);

			if (txtname != null)
				txtname.setText(player.getName());
			if (txtfirstname != null)
				txtfirstname.setText(player.getFirstname());
			if (txtnationality != null)
				txtnationality.setText(player.getNationality());
		}

		return v;

	}

}
